package com.imooc.reader.management.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

@Data
@TableName("user")
@NoArgsConstructor
@AllArgsConstructor

public class User implements UserDetails {
    @TableId(type = IdType.AUTO)
    private Integer userId;
    private String username;
    private String password;
    private Integer status;
    private String empName;
    private String deptName;


    public User(String username, String password, Integer status, String empName, String deptName) {
        this.username = username;
        this.password = password;
        this.status = status;
        this.empName = empName;
        this.deptName = deptName;
    }



    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return status == 1?true:false;
    }
}
